package com.qiqv.mybatisplus.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component // 交由spring托管
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("fill data start...");
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);
        log.info("fill data end...");
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("fill data start...");
        this.setFieldValByName("updateTime",new Date(),metaObject);
        log.info("fill data end...");
    }
}
